/*
 * @Author: mulingyuer
 * @Date: 2021-07-04 01:29:59
 * @LastEditTime: 2021-07-04 01:52:33
 * @LastEditors: mulingyuer
 * @Description: 自定义模板
 * @FilePath: \JJ\webpack\custom-template.js
 * 怎么可能会有bug！！！
 */
import type { EntryObject } from "webpack";
import HtmlWebpackPlugin from "html-webpack-plugin";

import { resolve } from "path";

// export default function (entry: EntryObject) {
// 	const cssArr: Array<HtmlWebpackPlugin> = [];
// 	const jsArr: Array<HtmlWebpackPlugin> = [];
// 	const keys = Object.keys(entry);

// 	keys.forEach((key) => {
// 		console.log(key);

// 		cssArr.push(
// 			new HtmlWebpackPlugin({
// 				template: resolve(__dirname, "./template/css.ejs"),
// 				filename: `${key}/css.php`,
// 				chunks: [key],
// 				inject: false, //自定义模板不需要自动注入
// 				// publicPath: "<?= TEMPLATE_URL ?>dist", //拼接php地址
// 				minify: {
// 					removeComments: true, //去除html注释
// 					collapseWhitespace: false, //去除换行
// 					minifyCSS: true //缩小样式元素和样式属性中css
// 				}
// 			})
// 		);
// 		jsArr.push(
// 			new HtmlWebpackPlugin({
// 				template: resolve(__dirname, "./template/script.ejs"),
// 				filename: `${key}/script.php`,
// 				chunks: [key],
// 				inject: false, //自定义模板不需要自动注入
// 				// publicPath: "<?= TEMPLATE_URL ?>dist", //拼接php地址
// 				minify: {
// 					removeComments: true, //去除html注释
// 					collapseWhitespace: false, //去除换行
// 					minifyCSS: true //缩小样式元素和样式属性中css
// 				}
// 			})
// 		);
// 	});

// 	return [...jsArr, ...cssArr];
// }

export const createJavascript = () => {
	return new HtmlWebpackPlugin({
		template: resolve(__dirname, "./template/script.ejs"),
		filename: `head/script.php`,
		inject: false, //自定义模板不需要自动注入
		publicPath: "<?= TEMPLATE_URL ?>dist", //拼接php地址
		minify: {
			removeComments: true, //去除html注释
			collapseWhitespace: false, //去除换行
			minifyCSS: true //缩小样式元素和样式属性中css
		}
	});
};

export const createCSS = () => {
	return new HtmlWebpackPlugin({
		template: resolve(__dirname, "./template/css.ejs"),
		filename: `head/css.php`,
		inject: false, //自定义模板不需要自动注入
		publicPath: "<?= TEMPLATE_URL ?>dist", //拼接php地址
		minify: {
			removeComments: true, //去除html注释
			collapseWhitespace: false, //去除换行
			minifyCSS: true //缩小样式元素和样式属性中css
		}
	});
};
